﻿using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EasyModbus;

namespace Utility
{
    public class ModBusHelper
    {

        public Uri node;
        //public ConnectionSettings connSettings;
        public static ModbusClient client;

        public void Connect( ModbusClient client, string ip, int port)
        {
            client.Connect(ip, port);
        }

        public void Disconnect( ModbusClient client)
        {
            client.Disconnect();
        }

        public bool Connected( ModbusClient client)
        {
            return client.Connected;
        }

        public bool[] ReadCoils( ModbusClient client, int startAddress, int length)
        {
            return client.ReadCoils(startAddress, length);
        }

        public bool[] ReadDiscreteInputs( ModbusClient client, int startAddress, int length)
        {
            return client.ReadDiscreteInputs(startAddress, length);
        }

        public int[] ReadHoldingRegisters( ModbusClient client, int startAddress, int length)
        {
            return client.ReadHoldingRegisters(startAddress, length);
        }

        public int[] ReadInputRegisters( ModbusClient client, int startAddress, int length)
        {
            return client.ReadInputRegisters(startAddress, length);
        }

        public void WriteSingleCoil( ModbusClient client, int address, bool value)
        {
            client.WriteSingleCoil(address, value);
        }

        public void WriteMultipleCoils( ModbusClient client, int startAddress, bool[] values)
        {
            client.WriteMultipleCoils(startAddress, values);
        }

        public void WriteSingleRegister( ModbusClient client, int address, int value)
        {
            client.WriteSingleRegister(address, value);
        }

        public void WriteMultipleRegisters( ModbusClient client, int startAddress, int[] values)
        {
            client.WriteMultipleRegisters(startAddress, values);
        }
    }

}
